﻿<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["CurrentOnine"] = 0;
        Application["TotalVisited"] = 0;
        Application["DayVisited"] = 0;
        Application["WeekVisited"] = 0;
        Application["MonthVisited"] = 0;
    }    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }
    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        Application.Lock();
        Application["CurrentOnine"] = int.Parse(Application["CurrentOnine"].ToString()) + 1;
        Application.UnLock();
        try
        {
            ReportUserOnline.prcUpdateReportUserOnline();
            System.Data.DataTable dt = ReportUserOnline.prcGetReportUserOnline();
            if (dt != null)
            {
                Application.Lock();
                Application["TotalVisited"] = int.Parse(dt.Rows[0]["VisitedTotal"].ToString());
                Application["DayVisited"] = int.Parse(dt.Rows[0]["VisitedDay"].ToString());
                Application["WeekVisited"] = int.Parse(dt.Rows[0]["VisitedWeek"].ToString());
                Application["MonthVisited"] = int.Parse(dt.Rows[0]["VisitedMonth"].ToString());
                Application.UnLock();
            }
        }
        catch
        {

        }
    }
    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        Application.Lock();
        Application["CurrentOnine"] = int.Parse(Application["CurrentOnine"].ToString()) - 1;
        Application.UnLock();
    }
       
</script>
